﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
//using System.Threading.Tasks;

namespace FaceSDKCShape
{
    class ZYFaceSDK
    {
        public const string ZYFaceSDKPath = "FaceSDKForWin.dll";
        /*
             The ZY_GetDevicesSerialNumber function will get the PC info and turn to EncryptionSerial,the EncryptionSerial
             must be given back to ZYTECHNOLOGY to get the decryptSerial code

             Parameters:
             EncryptionSerial[output],new [128] char* in
             mac[output],new [128] char* in
             cardstype[output] new [128] char* in
             error code:
             FACE_ERROR_SERAIL_P					-401
             FACE_SUCESS                 0
             Remarks:
             This function only can be called one time at program first used.
        */
        [DllImport(ZYFaceSDKPath, EntryPoint = "ZY_GetDevicesSerialNumber")]
        public static extern int ZY_GetDevicesSerialNumber(Byte[] EncryptionSerial, Byte[] mac, Byte[] cardstype);


        /*
	        The ZY_FaceSDKInit function will initialize the algorithm engine module
	        must be given back to ZYTECHNOLOGY to get the decryptSerial code

	        Parameters:
	        nChannelNums[intput],algorithm channel nums,for multi-thread mode,one thread uses one channel
	        decryptSerial[intput],the decryptSerial code get from ZYTECHNOLOGY
	        error code:
	        FACE_SUCESS                 0

	        FACE_ERROR_INITFAILED      -1
	        FACE_ERROR_MAXCHANNEL         -6
	        FACE_REPEAT_INITFAILED      -9
	        FACE_ERROR_SERAIL_P					-401
	        FACE_ERROR_DECRYPT_P				-402
	        FACE_ERROR_TIMEOUT					-403
	        FACE_ERROR_LOCAL_DECRYPT_P			-404
	        FACE_ERROR_LOCAL_DECRYPT_FILE_P      -405
	        FACE_ERROR_COMPARE_DECRYPT_FILE_P    -406
	        FACE_ERROR_NO_DECRYPT_P				-407
	        Remarks:
	        This function only can be called one time at  program initialization.
	    */
        [DllImport(ZYFaceSDKPath, EntryPoint = "ZY_FaceSDKInit")]
        public static extern int ZY_FaceSDKInit(int nChannelNums, Byte[] decryptSerial);

         /*
	        The ZY_DetectAndExtract function execute face detection and get face feature.

	        Parameters:
	        pdata[input],image data buffer,RGB24 format.
	        width[input],image width.
	        height[input],image height.
	        channel[input],bits per pixel(24-RGB24 image),must be 24
	        pFea[output],the face feature..
	        Return Values:
	        If the function succeeds, the return value is FACE_SUCESS
	        If the function fails, the return value is negative.
	        error code:
	        FACE_SUCESS                 0
	        FACE_ERROR_INITFAILED      -1
	        FACE_ERROR_MAXCHANNEL         -6
	        FACE_REPEAT_INITFAILED      -9
	        FACE_ERROR_SERAIL_P					-401
	        FACE_ERROR_DECRYPT_P				-402
	        FACE_ERROR_TIMEOUT					-403
	        FACE_ERROR_LOCAL_DECRYPT_P			-404
	        FACE_ERROR_LOCAL_DECRYPT_FILE_P      -405
	        FACE_ERROR_COMPARE_DECRYPT_FILE_P    -406
	        FACE_ERROR_NO_DECRYPT_P				-407
	        Remarks:
	        1.image data buffer(pImage)	size must be nWidth*(bpp/8)*nHeight.
	        2.pFea must be allocated by caller,the memory size is FATURE_SIZE
	        3.image data  have only have one face in
	    */
        [DllImport(ZYFaceSDKPath, EntryPoint = "ZY_DetectAndExtract")]
        public static extern int ZY_DetectAndExtract(IntPtr pdata, int width, int height, int channel, Byte[] pFea);

        /*
            The ZY_FaceSDKRelease function will release the algorithm engine module
            Parameters:
            No parameter.
            Return Values:
            No return value.
            Remarks:
            This function only can be called one time at program exit.
        */
        [DllImport(ZYFaceSDKPath, EntryPoint = "ZY_FaceSDKRelease")]
        public static extern int ZY_FaceSDKRelease();

        /*
    The ZY_FFCompara function will compara face feature
    Parameters:
    pFeaA[in],the face A feature..
    pFeaB[in],the face B feature..
    Return Values:
    face Similarly belong 0.0 to 1.0  default threshold is 0.68
    Remarks:
    This function only can be called one time at program exit.
    */
        [DllImport(ZYFaceSDKPath, EntryPoint = "ZY_FFCompara")]
        public static extern int ZY_FFCompara(Byte[] pFeaA, Byte[] pFeaB);
    }
}
